package cn.ezios.huo.system.biz.controller;

import cn.ezios.huo.system.dao.domain.SysUserAuthLog;
import cn.ezios.huo.system.dao.dto.SysUserAuthLogDTO;
import cn.ezios.huo.system.dao.vo.SysUserAuthLogVO;
import cn.ezios.huo.system.dao.service.SysUserAuthLogService;
import cn.ezios.huo.common.mvc.Ret;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("sys/user/auth/log")
@RequiredArgsConstructor
public class SysUserAuthLogController {

    private final SysUserAuthLogService sysUserAuthLogService;

    @PostMapping("")
    public Ret add(@RequestBody SysUserAuthLog sysUserAuthLog) {
        boolean save = sysUserAuthLogService.save(sysUserAuthLog);
        return save ? Ret.ok() : Ret.error();
    }

    @PutMapping("")
    public Ret update(@RequestBody SysUserAuthLog sysUserAuthLog) {
        boolean update = sysUserAuthLogService.updateById(sysUserAuthLog);
        return update ? Ret.ok() : Ret.error();
    }

    @GetMapping("{id}")
    public Ret get(@PathVariable("id") String id) {
        SysUserAuthLog sysUserAuthLog = sysUserAuthLogService.getById(id);
        return sysUserAuthLog != null ? Ret.ok(sysUserAuthLog) : Ret.error("未找到");
    }

    @GetMapping("page")
    public Ret page(@RequestParam(value = "current", defaultValue = "1") Integer current,
    @RequestParam(value = "size", defaultValue = "10") Integer size,SysUserAuthLogDTO dto) {
       IPage <SysUserAuthLogVO> page = sysUserAuthLogService.queryPage(current,size,dto);
            return Ret.ok(page);
    }

    @DeleteMapping("{id}")
    public Ret delete(@PathVariable("id") String id) {
        boolean remove = sysUserAuthLogService.removeById(id);
        return remove ? Ret.ok() : Ret.error();
    }
}
